package com.ioffice.export.excel;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;

public class ExportExcel {

	
	
	public static void main(String[] args) {
	
		String titles[]={"终端号","吞钞额","吞钞张数","操作时间","吞钞总金额","吞钞总张数"};
		
		try{
			
		HSSFWorkbook excel=new HSSFWorkbook();
		HSSFSheet  sheet=excel.createSheet("报表");
		
		//创建第一行
		HSSFRow row = sheet.createRow((short) 0); 
		sheet.addMergedRegion(new CellRangeAddress(0, (short) 0, 0, (short) 6));  
		HSSFCell ce = row.createCell(0);     
		ce.setCellValue("异常吞钞汇总表"); 
		ce.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
		
		//创建第二行
		HSSFRow row2 = sheet.createRow((short) 1);  
//		HSSFCell cell=null;
		for(int i=0;i<6;i++){
			HSSFCell cell = row2.createCell(i); 
			cell.setCellValue(titles[i]);
			cell.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
		}
		
		
		//创建第3行
		HSSFRow row3 = sheet.createRow((short) 2);   
		SheetUtils.mergerSheetCell(sheet, 0, 2, 1, 5);
		
		HSSFCell rw3cell = row3.createCell(0); 
		rw3cell.setCellValue("000001");
		rw3cell.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
		for(int i=1;i<4;i++){
			HSSFCell rwcell1 = row3.createCell(i); 
			rwcell1.setCellValue("000001");
			rwcell1.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
		}
		
		SheetUtils.mergerSheetCell(sheet, 4, 2, 1, 5);
		
		HSSFCell rw3cell4 = row3.createCell(4); 
		rw3cell4.setCellValue("总金额");
		rw3cell4.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
		
		SheetUtils.mergerSheetCell(sheet, 5, 2, 1, 5);
		
		HSSFCell rw3cell5 = row3.createCell(5); 
		rw3cell5.setCellValue("总数量");
		rw3cell5.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
		int rowNum=2+1;
		for(int i=0;i<4;i++){
			HSSFRow rows = sheet.createRow((short) rowNum++); 
			for(int j=0;j<3;j++){
				HSSFCell cell = rows.createCell(j+1); 
				cell.setCellValue("s"+j);
				cell.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
			}
		}
//		//第四行
//		HSSFRow row4 = sheet.createRow((short) 3);   
//		
//		HSSFCell rw4cell = row4.createCell(1); 
//		rw4cell.setCellValue("s");
//		rw4cell.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
//		HSSFCell rw4cell2 = row4.createCell(2); 
//		rw4cell2.setCellValue("ss");
//		rw4cell2.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
//		HSSFCell rw4cell3 = row4.createCell(3); 
//		rw4cell3.setCellValue("sss");
//		rw4cell3.setCellStyle(SheetUtils.getAlignmentCenterStyle(excel));
		
		
		OutputStream out=new FileOutputStream(new File("d:/text.xls"));
		 excel.write(out);
		}catch(Exception e){
			System.out.println(e.toString());
		}
	}
	
}
